package view.aluno;

import java.awt.BorderLayout;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.text.ParseException;

import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;

import model.pessoa.Aluno;
import model.produto.Produto;

import com.towel.el.annotation.AnnotationResolver;
import com.towel.swing.table.ObjectTableModel;

import controller.aluno.AlunoController;

import view.PesquisaMae;
import view.View;
import view.utils.PainelBotoes;

public class InstrutorPesquisa extends PesquisaMae implements View{
	
	private Aluno aluno;
	private JLabel lbNome, lbMatricula;
	private JTextField txNome, txMatricula;
	private ObjectTableModel<Aluno> tableModel;
	private AnnotationResolver resolver;
	private ActionListener controler;
	
	private JTable grid;
	private JPanel panelCentro;
	private JPanel panelNorte;

	public InstrutorPesquisa(ActionListener controller) {
		super("Aluno", 490, 600, controller);
		//this.controler = controller;
	}
	
	@Override
	protected void init() {
		super.init();
		
		resolver = new AnnotationResolver(Aluno.class);
		criarObjectTableModel();
		
		grid = new JTable(tableModel);
		
		lbNome = new JLabel("Nome:  ");
		lbMatricula= new JLabel("Matricula:  ");
		txNome = new JTextField(35);
		txMatricula = new JTextField();
		
		panelNorte = new JPanel();
		panelCentro = new JPanel();
	}
	
	@Override
	protected void setupComponentes() {
		super.setupComponentes();
		//JPanel painelAux = new JPanel();
		//JPanel painelAux2 = new JPanel();
		
		((PainelBotoes) this.getPainelBotoes()).getBtNovo().addActionListener(new AlunoController(this, null));
		
		((PainelBotoes) this.getPainelBotoes()).getBtPesquisar()
				.addActionListener(new AlunoController(this, new Aluno()));
		grid.addMouseListener(new AlunoController(this, null));
		
		JPanel aux1 = new JPanel(new GridLayout(2, 1));
		JPanel aux2 = new JPanel(new GridLayout(2, 1));
		JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
		JPanel aux4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
		
		//painelAux.setLayout(new GridLayout(2, 1));
		//painelAux2.setLayout(new GridLayout(2, 1));
		
		/*painelAux.add(lbNome);
		painelAux.add(lbMatricula);
		painelAux2.add(txNome);
		painelAux2.add(txMatricula);*/
		
		aux1.add(lbNome);
		aux1.add(lbMatricula);

		aux2.add(txNome);
		aux2.add(txMatricula);

		aux3.add(aux1);
		aux4.add(aux2);
		
		panelNorte.add(aux3, BorderLayout.WEST);
		panelNorte.add(aux4, BorderLayout.CENTER);
		
		panelCentro.add(new JScrollPane(grid));
		
		getPainelForm().add(panelNorte, BorderLayout.NORTH);
		getPainelForm().add(panelCentro, BorderLayout.CENTER);
		
		
	}
	
	@Override
	protected void setupLayout() {
		super.setupLayout();
		getPainelForm().setLayout(new BorderLayout());
		
		panelNorte.setLayout(new BorderLayout());
		panelCentro.setLayout(new FlowLayout());

	}
	
	public void exibir(){
		setVisible(true);
	}
	
	public void fechar(){
		dispose();
	}
	
	public void criarObjectTableModel() {
		tableModel = new ObjectTableModel<Aluno>(resolver, "matricula,nome,rg,cpf");
	}
	
	public static void main(String[] args) {
		new InstrutorPesquisa(null).exibir();
	}

}
